window.lpTag=window.lpTag||{};lpTag.taglets=lpTag.taglets||{};lpTag.taglets.LPWebSocketWrapper=lpTag.taglets.LPWebSocketWrapper||function(a){function b(){}function c(a){P=h(a);if(a){S||"string"!=typeof a.server||0===a.server.indexOf("ws")&&(M=a.server);"function"==typeof a.created&&T.push({cb:a.created,context:a.context});"function"==typeof a.message&&U.push({cb:a.message,context:a.context});"function"==typeof a.closed&&V.push({cb:a.closed,context:a.context});"object"==typeof a.ping&&i(a.ping);if(M){for(var b in $)$.hasOwnProperty(b)&&typeof a[b]==typeof $[b]&&($[b]=a[b]);return!!S||n($)}}}function d(){var a=!1;if(J)a=S;else{X=0;a=n()}return a}function e(){return S}function f(a){var b="N/A";try{b=y(a);if(e()){z();J.send(b)}else k("Socket not connected. [request="+b+"]","send")}catch(c){k("Unable to send request [exc="+(c.message||c)+", request="+b+"]","send")}}function g(){clearTimeout(L);clearTimeout(K);M="";u();T.length=0;U.length=0;V.length=0;W.length=0}function h(a){var b=void 0!==window.WebSocket,c=!(!a||!a.disableNativeWebSocketCheck),d=(""+window.WebSocket).indexOf("[native")>-1||(""+window.WebSocket).indexOf("WebSocketConstructor")>-1;return b&&(c||d)}function i(a){if("object"==typeof a&&a.request){Z.request=JSON.parse(y(a.request));Q=!0;if(a.response)Z.response=a.response;else if("object"==typeof a.keys&&"object"==typeof Z.request&&"string"==typeof a.keys.request&&"string"==typeof a.keys.response){Z.reqKey=a.keys.request;Z.resKey=a.keys.response}"function"==typeof a.callback&&W.push({cb:a.callback});(Z.response||Z.reqKey&&Z.resKey)&&(Z.timeout=a.timeout||$.pingTimeout);Z.idleBeforePing=a.idleBeforePing||$.idleBeforePing}}function j(a,b,c){if(window.lpTag&&lpTag.log){"string"==typeof a&&c&&(a=c+": "+a);lpTag.log(a,b,N)}}function k(a,b){j(a,_.ERROR,b)}function l(){if(X>=$.maxReconnectAttempt)w("cb",V,{state:"TERMINAL",code:503,message:"Socket terminal, will not reconnect"});else if($.autoReconnect&&M){L&&clearTimeout(L);L=setTimeout(function(){if(!n()){X+=1;l()}},m())}}function m(){var a;a=X1e3||b?500:200,reason:a.reason||"",domain:a.srcElement&&a.srcElement.url?a.srcElement.url:""}:null}function w(a,b,c){var d;if(b){d=b.constructor===Array?b:[b];for(var e=0;e0;)try{la.shift().call(null)}catch(a){Z("Unable to execute queued callbacks for window interactive state: "+a,ma.ERROR,"_attachPendingIFrames")}}function m(a){return a+"_"+Math.floor(1e5*Math.random())+"_"+Math.floor(1e5*Math.random())}function n(a){var b,c=new RegExp(/(http{1}s{0,1}?:\/\/)([^\/\?]+)(\/?)/gi),d=null;if(0!==a.indexOf("http"))return location.protocol+"//"+location.host;b=c.exec(a);b&&b.length>=3&&""!==b[2]&&(d=b[1].toLowerCase()+b[2].toLowerCase());return d}function o(a,b){var c,d,e=!1;if(!a||!a.url||"string"!=typeof a.url){Z("iFrame configuration empty or missing url parameter",ma.ERROR,"_queueFrame");return e}c=n(a.url);d=0===a.url.toLowerCase().indexOf("https");if(!(da[c]||ja[c]||b&&d!==b)){ja[c]=a;e=!0}return e}function p(a){var b=n(a.url);if(da[b])return w(b,a.callback||a.success,a.context);var c=m("fr");da[b]={elem:x(c),url:a.url,validated:ua.PENDING,defaults:a.defaults||{},delayLoad:isNaN(a.delayLoad)?0:a.delayLoad,requestCount:0,success:a.callback||a.success,error:a.error,maxReloadRetries:a.maxReloadRetries||3,reloadInterval:1e3*a.reloadInterval||3e4};setTimeout(function(){r(a.url,b)},da[b].delayLoad);Z("iFrame Queued to load "+b,ma.INFO,"_addFrame");return ua.PENDING}function q(a){var b=n(a.url);ja[b]={url:a.url,defaults:a.defaults||{},delayLoad:a.delayLoad,success:a.success,error:a.error,maxReloadRetries:a.maxReloadRetries,reloadInterval:a.reloadInterval/1e3}}function r(a,b){ka?s(a,b):la.push(function(){s(a,b)})}function s(a,b){da[b].loadCallback=da[b].loadCallback||t(b);S(da[b].elem,a);h(da[b].elem,"load",da[b].loadCallback);da[b].iFrameOnloadTimeout=setTimeout(da[b].loadCallback,ta);da[b].attachTime=(new Date).getTime();document.body.appendChild(da[b].elem)}function t(a){return function(b){if(da[a].iFrameOnloadTimeout){clearTimeout(da[a].iFrameOnloadTimeout);delete da[a].iFrameOnloadTimeout}da[a].loadTime=(new Date).getTime()-da[a].attachTime;A(a,b)}}function u(a){ga+=1;ia+=1;da[a].requestCount=da[a].requestCount+1}function v(a,b){fa[a]=fa[a]||[];fa[a].push(b);return!0}function w(a,b,c){W(b,c,f(a));return da[a].validated}function x(a){var b=document.createElement("IFRAME");b.setAttribute("id",a);b.setAttribute("name",a);b.setAttribute("tabindex","-1");b.setAttribute("aria-hidden","true");b.setAttribute("title","");b.setAttribute("role","presentation");b.style.width="0px";b.style.height="0px";b.style.position="absolute";b.style.top="-1000px";b.style.left="-1000px";b.style.display="none";return b}function y(a,b,c,d,e,f){var g=!1;if(a&&b&&"function"==typeof b){ea[a]={success:b,error:c,progress:d,ctx:e,launchTime:new Date,timeout:isNaN(f)?sa.timeout:f+1e3};g=!0}return g}function z(a){if(ea[a]){ea[a]=null;delete ea[a];return!0}return!1}function A(a,b){Z("onLoad validation called "+a,ma.INFO,"_validateFrame");var c=function(b){B(b,a)};b&&b.error?B(b,a):setTimeout(function(){e({domain:a,success:c,error:c,validation:!0,timeout:100,retries:-1,defaults:da[a].defaults})},10);return!0}function B(a,b){var c,d=da[b];Z("running validation of domain "+b,ma.INFO,"_validateFrameCallback");if(d){da[b].validated=a&&a.error?ua.FAILED:ua.VALIDATED;c=da[b].validated===ua.VALIDATED;c?C(b,a):da[b].reloadObj&&da[b].reloadObj.retriesLeft>0?E(b):D(b)}d=null;return c}function C(a,b){var c;Z("FrameLoaded "+a,ma.INFO,"_runFrameValidated");c=N(qa);for(var d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);W(da[a].success,da[a].context,c);U(a);F(a,!0)}function D(a){Z("iFrame is a teapot "+a,ma.ERROR,"_runFrameFailedToLoad");if(da[a].error){var b=i(0,ra);b.domain=a;W(da[a].error,da[a].context,b)}G(a);F(a,!1)}function E(a){Z("Retry loading domain: "+a,"info","_runReloadAttempt");F(a,!1);P(a)}function F(a,b){Z("Running buffer queue : "+a+" loaded: "+b,ma.INFO,"_runQueuedRequests");if(fa[a]&&fa[a].length>0){do{var c=fa[a].shift();b?e(c):W(c.error,c.context,{responseCode:600,error:"Transport - postmessage - unable to run request: "+a,body:"ERROR"})}while(fa[a].length>0);fa[a]=null;delete fa[a]}}function G(a){Z("Cleaning up failed iFrame: "+a,ma.INFO,"_cleanupIFrame");if(da[a]){j(da[a].elem,"load",da[a].loadCallback);da[a].elem.parentNode.removeChild(da[a].elem);var b=N(ra);b.domain=a;b.url=da[a].url;W(da[a].error,da[a].context,b);q(da[a]);da[a]=null;delete da[a]}}function H(a,b,c){Z("Frame not found for domain: "+a,ma.ERROR,"_noFrameFound");W(b,{responseCode:600,error:"Transport - postmessage - unable to run request: "+a,body:"ERROR"},c);return!1}function I(a){var b,c=!1;a=K(a);b=N(a);try{b=J(b)}catch(d){Z("Error trying to _stringify message",ma.ERROR,"sendMessageToFrame");return!1}Z("sending msg to domain "+a.domain,ma.DEBUG,"sendMessageToFrame");var e;isNaN(a.timeout)||isNaN(a.retries)||(e=a.timeout*(a.retries+1)+2e3);y(a.callId,a.success,a.error,a.progress,a.context,e);try{c=L(a.domain,b);_=setTimeout(M,1e3)}catch(d){Z("Error trying to send message: "+d,ma.ERROR,"sendMessageToFrame");c=!1}return c}function J(a){var b;if("function"==typeof Array.prototype.toJSON){var c=Array.prototype.toJSON;delete Array.prototype.toJSON;try{b=JSON.stringify(a)}catch(d){Array.prototype.toJSON=c;throw d}Array.prototype.toJSON=c}else b=JSON.stringify(a);return b}function K(b){var c=da[b.domain]&&da[b.domain].defaults;b.callId=m("call");b.returnDomain=na;void 0===b.timeout&&(b.timeout=c&&c.timeout||sa.timeout);void 0===b.retries&&(b.retries=c&&void 0!==c.retries?c.retries:sa.retries);b.progress&&(b.fireProgress=!0);b.headers=b.headers||{};b.headers["LP-URL"]=a.location.href;return b}function L(a,b){var c=!1;try{da[a].elem.contentWindow.postMessage(b,a);c=!0}catch(d){Z("Error trying to send message: "+d,ma.ERROR,"_postTheMessage")}return c}function M(){_&&clearTimeout(_);_=null;var a=new Date,b=0,c=[];for(var d in ea)if(ea.hasOwnProperty(d)&&ea[d].launchTime){var e=a-ea[d].launchTime;e>ea[d].timeout?c.push(d):b+=1}if(c.length){Z("Checking errors found "+c.length+" timeout callbacks to call",ma.DEBUG,"_checkForErrors");for(var f=0;f0&&(_=setTimeout(M,1e3));return!0}function N(a){var b=a;try{b=JSON.parse(J(a))}catch(c){}return b}function O(a,b){var c,d=ea[a.callId],e=a.responseType,f=!1;if(a.callId&&ea[a.callId]||a.responseType===oa.reloading||a.responseType===oa.stats)try{switch(e){case oa.completed:c=d.success;f=!0;break;case oa.error:c=d.error;f=!0;ha+=1;break;case oa.progress:c=d.progress;break;case oa.reloading:a=b;c=P;break;case oa.stats:c=$;a=a.rawData}if(f){z(a.callId);V(a);ia=ia>=0?0:ia-1}c&&"function"==typeof c&&W(c,d&&d.ctx||null,a);c=null;d=null}catch(g){Z("Error in executing callback: "+g,ma.ERROR,"_executeMessageCallback");return!1}return!0}function P(a){Z("Got reload request from "+a,ma.INFO,"_handleReload");da[a].validated=ua.PENDING;if(!da[a].reloadObj){Z("Creating reloadObj"+a,ma.DEBUG,"_handleReload");da[a].reloadObj=T(a)}Q(a)}function Q(a){Z("Reload try for domain "+a+" ,retries left "+da[a].reloadObj.retriesLeft,ma.INFO,"_reloadIFrame");da[a].reloadObj.retriesLeft=da[a].reloadObj.retriesLeft-1;da[a].reloadObj.setLocationTimeout&&clearTimeout(da[a].reloadObj.setLocationTimeout);if(da[a].reloadObj.retry)da[a].reloadObj.setLocationTimeout=setTimeout(R(a),da[a].reloadInterval);else{da[a].reloadObj.retry=!0;R(a)()}}function R(a){return function(){da[a].iFrameOnloadTimeout=setTimeout(function(){A(a,{error:{code:404,message:"Frame did not trigger load"}})},ta);S(da[a].elem,da[a].url)}}function S(a,b){b+=b.indexOf("?")>0?"&bust=":"?bust=";b+=(new Date).getTime();b+="&loc="+encodeURIComponent(location.protocol+"//"+location.host);Z("Setting iFrame to URL: "+b,ma.INFO,"_setIFrameLocation");a.setAttribute("src",b)}function T(a){Z("Creating reload object "+a,ma.INFO,"_createReloadObject");return{retriesLeft:da[a].maxReloadRetries}}function U(a){Z("Cleaning up reload object for this instance"+a,ma.INFO,"_cleanUpReloadObject");if(da[a].reloadObj){da[a].reloadObj.setLocationTimeout&&clearTimeout(da[a].reloadObj.setLocationTimeout);da[a].reloadObj=null;delete da[a].reloadObj}}function V(a){for(var b=["callId","responseType"],c=0;c-1&&this.events[a].splice(c,1)}}function d(a,b){var c=[].slice.call(arguments,1);if(this.events[a]instanceof Array)for(var d=this.events[a].slice(),e=d.length,f=0;e>f;f+=1)d[f].apply(this,c)}function e(a,b){this.on(a,function c(){this.removeListener(a,c);b.apply(this,arguments)})}this.events={};this.on=a;this.clearAllListeners=b;this.off=c;this.emit=d;this.once=e};window.lpTag=window.lpTag||{};lpTag.AMSUtils=lpTag.AMSUtils||function(){function a(a,b,d){try{"function"==typeof a&&a.call(d||null,b)}catch(e){c("Error executing callback","runCallBack")}}function b(a,b,c){window.lpTag&&window.lpTag.log&&window.lpTag.log(c+": "+a,b,x)}function c(a,c){b(a,z.ERROR,c)}function d(a,c){b(a,z.DEBUG,c)}function e(a,c){b(a,z.INFO,c)}function f(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function g(a,b){var c={};for(var d in b)c[d]=h(a,b[d]);return c}function h(a,b){for(var c=b.split("."),d=a,e=0;e-1;if(c||e){b.tokenIsInvalid=!0;d()}B.runCallBack(a,b)}}function p(){L.inProgress=!1;L.values=K}function q(b){v&&clearTimeout(v);if(D)if(b)if(L.enabled){L.inProgress=!0;var c=L.values;if(c.auth){c.auth=c.auth-1;B.error("Token has expired on rest call. data: "+JSON.stringify(b),z);B.runCallBack(a.onSessionInvalidated,null,b)}else if(c.stage1){c.stage1=c.stage1-1;v=setTimeout(s,w.pollingInterval)}else if(c.stage2){c.stage2=c.stage2-1;v=setTimeout(s,c.stage2Interval)}else p()}else v=setTimeout(s,w.pollingInterval);else{L.inProgress&&p();v=setTimeout(s,w.pollingInterval)}}function r(a){var b={url:B.templateStrings(I.restPath,w),headers:{Authorization:g()},method:"POST",data:a,success:function(a){if(a&&a.body&&a.body.length)for(var b=0;b=2){a.queryParameters=a.queryParameters||{};a.queryParameters.integrationVersion=Za}Qa()?c(a):pa(a);a.throttlingSupportEnabled&&(ub.enabled=!0);isNaN(a.throttlingTimeoutValue)||(ub.value=parseInt(a.throttlingTimeoutValue,10))}}function c(a){qa();a.onSocketCreated=oa.bind(this,a);pa(a)}function d(a){Ta&&Ta.closeConnection&&Ta.closeConnection();pb.unregister({appName:Ya});b(a)}function e(){return La(Ma(ob.requests.GET_CLOCK))}function f(a){switch(a.kind){case ob.messageKinds.NOTIFICATION:ua(a);break;case ob.messageKinds.RESPONSE:va(a)}}function g(a){if(nb.validateConditions({dialogId:{type:nb.validationTypes.STRING},conversationId:{type:nb.validationTypes.STRING}},a)){var b={dialogId:a.dialogId,conversationId:a.conversationId,event:{type:ob.eventTypes.CONTENT,contentType:a.contentType||"text/plain",message:a.text,quickReplies:a.quickReplies}};a.messageAudience&&(b.messageAudience=a.messageAudience);var c=Ma(ob.requests.PUBLISH_EVENT,b,a.metadata);a.retryOnError=!0;return La(c,a)}}function h(a){return nb.validateConditions({dialogId:{type:nb.validationTypes.STRING},conversationId:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.PUBLISH_EVENT,{dialogId:a.dialogId,conversationId:a.conversationId,event:{type:ob.eventTypes.CONTENT,contentType:a.contentType,message:{formId:a.formId,submissionId:a.submissionId,invitationId:a.invitationId,title:a.title}}}),a):void 0}function i(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},dialogId:{type:nb.validationTypes.STRING},json:{type:nb.validationTypes.OBJECT}},a)?La(Ma(ob.requests.PUBLISH_EVENT,{conversationId:a.conversationId,dialogId:a.dialogId,event:{type:ob.eventTypes.RICH_CONTENT,content:a.json,quickReplies:a.quickReplies}},a.metadata),a):void 0}function j(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING}},a)?La(Ma(".ams.ms.GenerateURLForDownloadFile",{dialogId:a.conversationId,relativePath:a.pathUrl}),a):void 0}function k(a){var b,c;if(nb.validateConditions({dialogId:{type:nb.validationTypes.STRING},conversationId:{type:nb.validationTypes.STRING},chatState:{type:nb.validationTypes.ENUM,expected:ob.chatStates}},a)){c={dialogId:a.dialogId,conversationId:a.conversationId,event:{type:ob.eventTypes.CHAT_STATE,chatState:a.chatState.toUpperCase()}};b=a.chatState===ob.chatStates.SIGNALED?Ma(ob.requests.PUBLISH_EVENT,c,a.metadata):Ma(ob.requests.PUBLISH_EVENT,c);return La(b,a)}}function l(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},conversationState:{type:nb.validationTypes.ENUM,expected:ob.conversation.states}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:a.field||ob.conversationFields.CONVERSATION_STATE,conversationState:a.conversationState||ob.conversation.states.CLOSE}}),a):void 0}function m(a){a.conversationState=ob.conversation.states.CLOSE;l(a)}function n(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},userId:{type:nb.validationTypes.STRING},role:{type:nb.validationTypes.ENUM,expected:ob.participant.roles},changeType:{type:nb.validationTypes.ENUM,expected:ob.fieldsChangeTypes}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.PARTICIPANTS_CHANGE,type:a.changeType,userId:a.userId,role:a.role,dialogId:nb.getDialogIdFromMessageRequest(a)}}),a):void 0}function o(a){if(nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},authUserId:{type:nb.validationTypes.STRING},unAuthUserId:{type:nb.validationTypes.STRING}},a)){var b=Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:[{field:ob.conversationFields.PARTICIPANTS_CHANGE,type:ob.fieldsChangeTypes.REMOVE,userId:a.unAuthUserId,role:ob.participant.roles.CONSUMER},{field:ob.conversationFields.PARTICIPANTS_CHANGE,type:ob.fieldsChangeTypes.ADD,userId:a.authUserId,role:ob.participant.roles.CONSUMER}]});Va=b.id;return La(b,a)}}function p(a){if(nb.validateConditions({ownerId:{type:nb.validationTypes.STRING},conversationId:{type:nb.validationTypes.STRING},skillId:{type:nb.validationTypes.STRING},accountId:{type:nb.validationTypes.STRING,optional:!0}},a)){var b=[];a.accountId&&""!==a.accountId&&b.push({field:ob.conversationFields.CONVERSATION_HANDLER,accountId:a.accountId});a.ownerId&&""!==a.ownerId&&b.push({field:ob.conversationFields.PARTICIPANTS_CHANGE,type:ob.fieldsChangeTypes.REMOVE,userId:a.ownerId,role:ob.participant.roles.ASSIGNED_AGENT,dialogId:nb.getDialogIdFromMessageRequest(a)});b.push({field:ob.conversationFields.SKILL,type:ob.fieldsChangeTypes.UPDATE,skill:a.skillId});return La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:b}),a)}}function q(a){if(nb.validateConditions({conversationId:{type:nb.validationTypes.STRING,optional:!1},dialogId:{type:nb.validationTypes.STRING,optional:!1},ownerId:{type:nb.validationTypes.STRING,optional:!0},ownerRole:{type:nb.validationTypes.ENUM,optional:!0,expected:ob.participant.roles},suggestedAgentId:{type:nb.validationTypes.STRING,optional:!1},skillId:{type:nb.validationTypes.STRING,optional:!0}},a)){var b=[{field:ob.conversationFields.PARTICIPANTS_CHANGE,type:ob.fieldsChangeTypes.SUGGEST,userId:a.suggestedAgentId,role:ob.participant.roles.ASSIGNED_AGENT}];a.ownerId&&a.ownerRole&&b.push({field:ob.conversationFields.PARTICIPANTS_CHANGE,type:ob.fieldsChangeTypes.REMOVE,userId:a.ownerId,role:a.ownerRole});a.skillId&&b.push({field:ob.conversationFields.SKILL,type:ob.fieldsChangeTypes.UPDATE,skill:a.skillId});return La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,dialogId:a.dialogId,conversationField:b}),a)}}function r(a){if(nb.validateConditions({ownerId:{type:nb.validationTypes.STRING},conversationId:{type:nb.validationTypes.STRING},agentId:{type:nb.validationTypes.STRING}},a)){var b=[],c=nb.getDialogIdFromMessageRequest(a);a.ownerId&&""!==a.ownerId&&b.push({field:ob.conversationFields.PARTICIPANTS_CHANGE,type:ob.fieldsChangeTypes.REMOVE,userId:a.ownerId,role:ob.participant.roles.ASSIGNED_AGENT,dialogId:c});b.push({field:ob.conversationFields.PARTICIPANTS_CHANGE,type:ob.fieldsChangeTypes.UPDATE,userId:a.agentId||"",role:ob.participant.roles.ASSIGNED_AGENT,dialogId:c});return La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:b}),a)}}function s(a){a.role=ob.participant.roles.ASSIGNED_AGENT;a.changeType=ob.fieldsChangeTypes.REMOVE;return n(a)}function t(a){if(nb.validateConditions({userId:{type:nb.validationTypes.STRING}},a)){var b={};a&&a.userId&&(b.userId=a.userId);return La(Ma(ob.requests.GET_USER_PROFILE,b),a)}}function u(a){return La(Ma(ob.requests.GET_USER_PROFILE),a)}function v(a,b){return La(Ma(ob.requests.GENERATE_UPLOAD_TOKEN,b),a)}function w(a){return La(Ma(ob.requests.GENERATE_DOWNLOAD_TOKEN,{downloadable:{type:"SecureForm",dialogId:a.dialogId,submissionId:a.submissionId,invitationId:a.invitationId}}),a)}function x(a){if(nb.validateConditions({agentUserId:{type:nb.validationTypes.STRING},availability:{type:nb.validationTypes.STRING}},a)){var b=ob.requests.SET_AGENT_STATUS,c=a.metadata,d={channels:["MESSAGING"]};d.agentUserId=a.agentUserId;d.availability=a.availability;return La(Ma(b,d,c),a)}}function y(a){if(nb.validateConditions({agentUserId:{type:nb.validationTypes.STRING},availability:{type:nb.validationTypes.STRING},isBlended:{type:nb.validationTypes.STRING}},a)){var b=ob.requests.SET_AGENT_STATUS,c=a.metadata,d={channels:["MESSAGING"]};d.agentUserId=a.agentUserId;d.availability=a.availability;d.isBlended=a.isBlended;return La(Ma(b,d,c),a)}}function z(a){if(nb.validateConditions({agentUserId:{type:nb.validationTypes.STRING},availability:{type:nb.validationTypes.STRING}},a)){var b=ob.requests.SET_AGENT_STATUS,c=a.metadata,d={channels:["MESSAGING"]};d.agentUserId=a.agentUserId;d.availability=a.availability;return La(Ma(b,d,c),a)}}function A(a){if(nb.validateConditions({agentUserId:{type:nb.validationTypes.STRING},isBlended:{type:nb.validationTypes.STRING}},a)){var b=ob.requests.GET_AGENT_STATUS,c=a.metadata,d={channels:["MESSAGING"]};d.agentUserId=a.agentUserId;d.isBlended=a.isBlended;return La(Ma(b,d,c),a)}}function B(a){if(nb.validateConditions({agentUserId:{type:nb.validationTypes.STRING},isBlended:{type:nb.validationTypes.STRING}},a)){var b=ob.requests.AGENT_SESSION_START,c=a.metadata,d={channels:["MESSAGING"]};d.agentUserId=a.agentUserId;d.isBlended=a.isBlended;return La(Ma(b,d,c),a)}}function C(a){if(nb.validateConditions({agentUserId:{type:nb.validationTypes.STRING},isBlended:{type:nb.validationTypes.STRING}},a)){var b=ob.requests.AGENT_SESSION_END,c=a.metadata,d={channels:["MESSAGING"]};d.agentUserId=a.agentUserId;d.isBlended=a.isBlended;return La(Ma(b,d,c),a)}}function D(a){if(nb.validateConditions({brandId:{type:nb.validationTypes.STRING},agentId:{type:nb.validationTypes.STRING}},a)){var b=ob.requests.SUBSCRIBE_AGENT_STATUS,c={};c.brandId=a.brandId;c.agentId=a.agentId;c.agentAvailability="";return La(Ma(b,c),a)}}function E(a){var b={userId:{type:nb.validationTypes.STRING,optional:!1},firstName:{type:nb.validationTypes.STRING,optional:!0},lastName:{type:nb.validationTypes.STRING,optional:!0},avatarUrl:{type:nb.validationTypes.STRING,optional:!0},email:{type:nb.validationTypes.STRING,optional:!0},phone:{type:nb.validationTypes.STRING,optional:!0},backgndImgUri:{type:nb.validationTypes.STRING,optional:!0}};return nb.validateConditions(b,a)?La(Ma(ob.requests.SET_USER_PROFILE,{firstName:a.firstName,lastName:a.lastName,userId:a.userId,avatarUrl:a.avatarUrl,backgndImgUri:a.backgndImgUri,role:ob.participant.roles.CONSUMER,privateData:{mobileNum:a.phone,mail:a.email}}),a):void 0}function F(a){return La(Ma(".InitConnection",null,null,[{type:ob.requests.INIT_CONNECTION_TOKEN,bearerToken:a}]),{})}function G(a){return nb.validateConditions({firstName:{type:nb.validationTypes.STRING},lastName:{type:nb.validationTypes.STRING},userId:{type:nb.validationTypes.STRING},avatarUrl:{type:nb.validationTypes.STRING},email:{type:nb.validationTypes.STRING},phone:{type:nb.validationTypes.NUMBER},apns:{type:nb.validationTypes.STRING},certName:{type:nb.validationTypes.STRING},token:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.SET_USER_PROFILE,{firstName:a.firstName,lastName:a.lastName,userId:a.userId,authenticatedData:a.authenticatedData,avatarUrl:a.avatarUrl,role:a.role||ob.participant.roles.ASSIGNED_AGENT,backgndImgUri:a.backgndImgUri,description:a.description,privateData:{mobileNum:a.phone,mail:a.email,pushNotificationData:{serviceName:a.apns,certName:a.certName,token:a.token}}}),a):void 0}function H(a){function b(){return a&&a.campaignInfo&&a.campaignInfo.campaignId&&a.campaignInfo.engagementId?{campaignId:a.campaignInfo.campaignId,engagementId:a.campaignInfo.engagementId}:null}function c(){return a&&a.conversationContext&&a.conversationContext.subscription?[{type:"NetworkEffect",contentProviderAccountId:a.conversationContext.subscription.provideraccountid,conversationOwnerId:a.conversationContext.subscription.conversationowneraccountid,referenceId:a.conversationContext.subscription.referenceid}]:null}var d,e,f;a=a||{};var g={skillId:a.skillId||"-1",channelType:a.channelType||ob.channelTypes.MESSAGING,ttrDefName:null,campaignInfo:b()},h=c();switch(fb.memberType){case ob.memberTypes.USER:if(Qa()||nb.validateConditions({brandId:{type:nb.validationTypes.STRING}},a)){d=ob.requests.REQUEST_CONVERSATION_CONSUMER;g.brandId=a.brandId;g.skillId=a.skillId||"-1";g.channelType=a.channelType;g.conversationContext={visitorId:a.conversationContext.visitorId,sessionId:a.conversationContext.sessionId,interactionContextId:a.conversationContext.interactionContextId,type:a.conversationContext.type,lang:a.conversationContext.lang}}break;case ob.memberTypes.AGENT:if(nb.validateConditions({consumerId:{type:nb.validationTypes.STRING}},a)){d=ob.requests.REQUEST_CONVERSATION_AGENT;g.consumerId=a.consumerId;g.conversationContext={type:"ProactiveContext",originConversationId:a.conversationId,originConversationContext:a.originContext};e=a.originContext&&a.originContext.lang;f=a.lang||e;f&&(g.conversationContext.lang=f)}}return d?La(Ma(d,g,h),a):void 0}function I(a){if(nb.validateConditions({brandId:{type:nb.validationTypes.STRING},agentId:{type:nb.validationTypes.STRING}},a)&&nb.validateConditions({memberType:{type:nb.validationTypes.CUSTOM,expected:ob.memberTypes.AGENT}},fb)){var b=Ma(ob.requests.SUBSCRIBE_ROUTING_TASKS,{brandId:a.brandId,agentId:a.agentId,channelType:ob.channelTypes.MESSAGING});a.skillId&&(b.body.skillId=a.skillId);a.conversationId&&(b.body.conversationId=a.conversationId);return La(b,a)}}function J(a){if(nb.validateConditions({subscriptionId:{type:nb.validationTypes.STRING},brandId:{type:nb.validationTypes.STRING},agentId:{type:nb.validationTypes.STRING}},a)&&nb.validateConditions({memberType:{type:nb.validationTypes.CUSTOM,expected:ob.memberTypes.AGENT}},fb)){var b=Ma(ob.requests.UPDATE_ROUTING_SUBSCRIPTION,{subscriptionId:a.brandId,brandId:a.brandId,agentId:a.agentId});a.skillId&&(b.body.skillId=a.skillId);a.conversationId&&(b.body.conversationId=a.conversationId);a.channelType&&(b.body.channelType=a.channelType);return La(b,a)}}function K(a){return nb.validateConditions({ringId:{type:nb.validationTypes.STRING}},a)&&nb.validateConditions({memberType:{type:nb.validationTypes.CUSTOM,expected:ob.memberTypes.AGENT}},fb)?La(Ma(ob.requests.UPDATE_RING_STATE,{ringId:a.ringId,ringState:"ACCEPTED"}),a):void 0}function L(a){return nb.validateConditions({ringId:{type:nb.validationTypes.STRING}},a)&&nb.validateConditions({memberType:{type:nb.validationTypes.CUSTOM,expected:ob.memberTypes.AGENT}},fb)?La(Ma(ob.requests.UPDATE_RING_STATE,{ringId:a.ringId,ringState:"REJECTED"}),a):void 0}function M(a){if(nb.validateConditions({dialogId:{type:nb.validationTypes.STRING},conversationId:{type:nb.validationTypes.STRING}},a)){var b=Ma(ob.requests.SUBSCRIBE_MESSAGING_EVENTS,{dialogId:a.dialogId,conversationId:a.conversationId,fromSeq:a.fromSeq||0});rb[b.id]=a.dialogId;tb.push(a.dialogId);return La(b,a)}}function N(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},dialogId:{type:nb.validationTypes.STRING}},a)?ta(a,{maxQuantity:a.maxQuantity||_a,olderThan:a.olderThan,newerThan:a.newerThan}):void 0}function O(a){if(nb.validateConditions({conversationId:{type:nb.validationTypes.STRING}},a)){var b=a.maxQuantity||_a,c=a.lastId||b,d=c-b;0>d&&(d=0);return ta(a,{maxQuantity:b,olderThan:c,newerThan:d})}}function P(a){if(nb.validateConditions({conversationId:{type:nb.validationTypes.STRING}},a)){var b=a.maxQuantity||_a,c=a.lastId||0;return ta(a,{maxQuantity:b,olderThan:c+b,newerThan:c})}}function Q(a){a.state=a.state.toUpperCase();if(nb.validateConditions({dialogId:{type:nb.validationTypes.STRING},conversationId:{type:nb.validationTypes.STRING},state:{type:nb.validationTypes.ENUM,expected:ob.messageState}},a)){var b=Ma(ob.requests.PUBLISH_EVENT,{dialogId:a.dialogId,conversationId:a.conversationId,event:{type:ob.eventTypes.ACCEPT_STATUS,status:a.state,sequenceList:a.sequenceList&&a.sequenceList.constructor===Array?a.sequenceList:[a.sequenceList]}},a.metadata);a.retryOnError=!0;return La(b,a)}}function R(a){return nb.validateConditions({brandId:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.GET_BRAND_PROFILE,{brandId:a.brandId}),a):void 0}function S(a){if(nb.validateConditions({brandId:{type:nb.validationTypes.STRING},name:{type:nb.validationTypes.STRING},description:{type:nb.validationTypes.STRING},category:{type:nb.validationTypes.STRING},dateJoined:{type:nb.validationTypes.NUMBER},lastUpdated:{type:nb.validationTypes.NUMBER},logoImg:{type:nb.validationTypes.STRING},backgroundImg:{type:nb.validationTypes.STRING}},a)){var b=Ma(ob.requests.SET_BRAND_PROFILE);nb.overRideMerge(b.body,a);return La(b,a)}}function T(a){return nb.validateConditions({memberType:{type:nb.validationTypes.CUSTOM,expected:ob.memberTypes.USER}},fb)?La(Ma(ob.requests.GET_BRANDS,{fromTimestamp:a.fromTimestamp}),a):void 0}function U(a){if(Qa()||nb.validateConditions({brandId:{type:nb.validationTypes.STRING}},a)){var b={brandId:a.brandId,minLastUpdatedTime:a.minLastUpdatedTime,agentIds:a.agentIds,groupIds:a.groupIds,consumerId:a.consumerId,stage:a.stage||a.convState||qb};a.stage||(b.convState=a.convState||qb);var c=Ma(ob.requests.SUBSCRIBE_CONVERSATIONS,b);a.maxLastUpdatedTime&&(c.body.maxLastUpdatedTime=a.maxLastUpdatedTime);a.maxETTR&&(c.body.maxETTR=a.maxETTR);a.conversationId&&(c.body.conversationId=a.conversationId);return La(c,a)}}function V(a){return nb.validateConditions({subscriptionId:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.UNSUBSCRIBE_CONVERSATIONS,{subscriptionId:a.subscriptionId}),a):void 0}function W(a){return nb.validateConditions({brandId:{type:nb.validationTypes.STRING},subscriptionId:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.SUBSCRIBE_CONVERSATIONS,{brandId:a.brandId,maxLastUpdatedTime:a.maxLastUpdatedTime,minLastUpdatedTime:a.minLastUpdatedTime,agentIds:a.agentIds,groupIds:a.groupIds,consumerId:a.consumerId,maxETTR:a.maxETTR,stage:a.convState||qb,convState:a.convState||qb,subscriptionId:a.subscriptionId}),a):void 0}function X(a){var b,c;if(nb.validateConditions({conversationId:{type:nb.validationTypes.STRING}},a)){b={conversationId:a.conversationId,conversationField:a.CSAT};b.conversationField.field=ob.conversationFields.CSAT_RATE;c=Ma(ob.requests.UPDATE_CONVERSATION,b);return La(c,a)}}function Y(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},delayType:{type:nb.validationTypes.ENUM,expected:ob.delayTypes},tillWhen:{type:nb.validationTypes.NUMBER}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.DELAY,type:a.delayType,tillWhen:a.tillWhen}}),a):void 0}function Z(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.MANUAL_ETTR,time:a.time||null}}),a):void 0}function $(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},ttrType:{type:nb.validationTypes.ENUM,expected:ob.effectiveTTRTypes},value:{type:nb.validationTypes.NUMBER,optional:!0}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.TTR,ttrType:a.ttrType,value:a.value||0}}),a):void 0}function _(a){return nb.validateConditions({note:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.NOTE,note:a.note}}),a):void 0}function aa(a){return nb.validateConditions({topic:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.TOPIC,note:a.topic}}),a):void 0}function ba(a){da(a,ob.dialogActions.CREATE)}function ca(a){da(a,ob.dialogActions.UPDATE)}function da(a,b){nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},dialogId:{type:nb.validationTypes.STRING}},a)&&La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.DIALOG_CHANGE,type:b||ob.dialogActions.CREATE, dialogId:a.dialogId,dialog:a.dialog}}),a)}function ea(a){return nb.validateConditions({conversationId:{type:nb.validationTypes.STRING},dialogId:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.UPDATE_CONVERSATION,{conversationId:a.conversationId,conversationField:{field:ob.conversationFields.DIALOG_CHANGE,type:ob.dialogActions.UPDATE,dialog:{dialogId:a.dialogId,state:ob.dialog.states.CLOSE,closedCause:a.closedCause}}}),a):void 0}function fa(){return fb&&fb.serverTimeDiff}function ga(a){return nb.validateConditions({fileSize:{type:nb.validationTypes.STRING},fileType:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.GENERATE_UPLOAD_FILE_URL,{fileSize:a.fileSize,fileType:a.fileType}),a):void 0}function ha(a){return nb.validateConditions({relativePath:{type:nb.validationTypes.STRING}},a)?La(Ma(ob.requests.GENERATE_DOWNLOAD_FILE_URL,{relativePath:a.relativePath}),a):void 0}function ia(){return Ta}function ja(){Ta&&Ta.closeConnection&&Ta.closeConnection();pb.unregister({appName:Ya});pb=null}function ka(){return!Ta||!Ta.isConnected||Ta.isConnected()}function la(){return!Ta||!Ta.isWebSocketConnection||Ta.isWebSocketConnection()}function ma(){clearTimeout(Sa);var a=new Date,b=0,c=[];for(var d in db)if(db.hasOwnProperty(d)&&db[d].launchTime){var e=a-db[d].launchTime;e>db[d].timeout?c.push(d):b++}if(c.length){nb.error("Checking errors found "+c.length+" timeout callbacks to call",Ya);for(var f=0;f0&&(Sa=setTimeout(ma,hb));return!0}function na(a,b,c){if(db[a]){c.retries=c.retries||0;if(c.retries=0){tb.splice(tb.indexOf(b),1);a.body.firstNotification=!0;a.body.subscriptionId&&(a.body.dialogId=sb[a.body.subscriptionId])}za(c,a.body)}za(ob.events.MSG_RECEIVE,{})}function va(a){var b=null;switch(a.type){case ob.responses.GET_CLOCK:Ha(a.body);break;case ob.responses.GET_USER_PROFILE:Ia(a.body);break;default:b=ob.responses[a.type]}if(Qa()){if(Ua===a.reqId)za(ob.events.INITIALIZED,a);else if(rb[a.reqId]){a.body.subscriptionId&&(sb[a.body.subscriptionId]=rb[a.reqId]);za(ob.events.SUBSCRIBE_MESSAGING_RESPONSE,a)}else if(Va===a.reqId)za("onConversationStepUp",a);else if(b){b===ob.events.BRAND_PROFILE&&(a.body.timeDiff=fa());za(b,a.body,a.reqId)}}else b&&za(b,a.body,a.reqId);wa(a);za(ob.events.MSG_RECEIVE,{})}function wa(a){if(void 0!==a.code&&a.code>399){var b=a.body;if(429===a.code){"object"!=typeof b&&(b={});b.throttling=!0;vb.emit(lpTag.AMSStatics.EVENT_EMITTER_EVENTS.ON_THROTTLED_BY_SERVER,a)}Ba(a.reqId,b,!0)}else Ba(a.reqId,a.body,!1)}function xa(a){var b,c;for(var d in a)if(a.hasOwnProperty(d)&&0===d.indexOf("on")){b=a[d];c=b.constructor===Array?b:[b];for(var e=0;e0&&(db[a].retryInProgress=setTimeout(na.bind(this,a,b,c),jb));Sa=setTimeout(ma,hb)}}function Ba(a,b,c){if(db[a]){nb.runCallBack(c?db[a].error:db[a].success,b,db[a].context);Ja(a)}}function Ca(b){ab=!0;"2.5"===$a&&F(Ta.getToken());e();Qa()&&nb.runCallBack(a.onSocketCreated,{token:Ta.getToken()});za(ob.events.CONNECTED,b||{connected:!0,ts:(new Date).getTime()});Na()}function Da(a){ab=!0;a&&200===a.responseCode&&(a.code=200);za(ob.events.INITIALIZED,a)}function Ea(a){ab=!1;Fa();a&&a.tokenIsInvalid&&za(ob.events.SESSION_INVALIDATED,{userId:fb.userId||null});za(ob.events.CLOSED,a||{connected:!1,ts:(new Date).getTime()})}function Fa(){for(var a in db)db.hasOwnProperty(a)&&Ba(a,mb,!0)}function Ga(a){za(ob.events.AUTHENTICATION_ERROR,a)}function Ha(a){a&&a.currentTime&&(fb.serverTimeDiff=(new Date).getTime()-a.currentTime)}function Ia(a){var b=nb.remodel(a,{userId:"userId",firstName:"firstName",lastName:"lastName",authenticatedData:"authenticatedData",imgUrl:"avatarUrl",role:"role",backgroundImage:"backgndImgUri",phone:"privateData.mobileNum",mail:"privateData.mail",description:"description",isDeleted:"isDeleted"});za(ob.events.USER_INFO,b)}function Ja(a){for(var b in db[a])if(db[a].hasOwnProperty(b)){"retryInProgress"===b&&clearTimeout(db[a][b]);db[a][b]=null;delete db[a][b]}db[a]=null;delete db[a]}function Ka(){eb.forEach(function(a){La(a.request,a.options)});eb=[]}function La(a,b){if(a){b=b||{};if(!b.errorHasWrapper){b.errorHasWrapper=!0;b.error=Oa(a,b)}if(ub.inAction)eb.push({request:a,options:b});else if(!ab&&cb)bb.push({request:a,options:b});else{Aa(a.id,a,b);Ta.sendMessage(a)}return a.id}}function Ma(a,b,c,d){var e={kind:ob.messageKinds.REQUEST,id:nb.getUID(),type:a,body:b||{}};c&&(e.metadata=c);d&&(e.headers=d);return e}function Na(){for(var a;bb.length>0&&ab;){a=bb.shift();La(a.request,a.options)}}function Oa(a,b){var c=b.error;return function(d){b.failure="number"==typeof b.failure?b.failure:0;if(ub.enabled&&d.throttling){ub.inAction=!0;clearTimeout(Wa);Wa=setTimeout(function(){ub.inAction=!1;Ka()},ub.value);La(a,b)}else if((b.retryOnError||cb&&d.timeout)&&b.failure<=kb){b.failure++;cb&&d.timeout?bb.push({request:a,options:b}):setTimeout(function(){La(a,b)},lb)}else nb.runCallBack(c,d,b.context)}}function Pa(a){return function(b,c){ya(a,b,c,Ya)}}function Qa(){return 3===$a}function Ra(a){var b=nb.getProperty(a,"body.event.type")===ob.eventTypes.CONTENT;return a&&a.type===ob.requests.PUBLISH_EVENT&&b}var Sa,Ta,Ua,Va,Wa,Xa,Ya="AMSClient",Za="3.0.91",$a=2,_a=200,ab=!1,bb=[],cb=!1,db={},eb=[],fb={},gb=1e4,hb=1e3,ib=1,jb=5e3,kb=3,lb=200,mb={timeout:"Request has timed out"},nb=lpTag.AMSUtils(),ob=nb.clone(lpTag.AMSStatics),pb=new lpTag.Chronos.Events,qb=nb.getValues(ob.conversation.states),rb={},sb={},tb=[],ub={enabled:!1,value:1e3,inAction:!1},vb=new lpTag.AMSEventEmitter,wb=!0,xb=15e3;b(a);this.name=Ya;this.v=Za;this.apiVersion=$a;this.init=b;if(Qa()){this.subscribeMessagingEvents=M;this.generateURLForDownloadFile=ha}else{this.queryMessages=O;this.queryMessagesNewerThan=P;this.newQueryMessages=N}this.reInit=d;this.initConnectionToken=F;this.getTimeDiff=fa;this.dispose=ja;this.getClock=e;this.handleMessage=f;this.sendMessage=g;this.sendPCIMessage=h;this.sendStructuredContentMessage=i;this.imageMessage=j;this.setDialogChatState=k;this.setConversationState=l;this.closeConversation=m;this.changeConversationParticipant=n;this.updateConversationParticipantForStepUp=o;this.unassignConversation=s;this.setAgentStatus=z;this.setAgentStatusWithIsBlended=y;this.setAgentStatusWithoutIsBlended=x;this.getAgentStatus=A;this.agentSessionStart=B;this.agentSessionEnd=C;this.subscribeAgentStatusUpdates=D;this.getUserProfile=t;this.getMyUserProfile=u;this.generateUploadToken=v;this.generateDownloadToken=w;this.setUserProfile=G;this.setConsumerProfileOnBehalfOfAgent=E;this.createConversation=H;this.takeConversation=K;this.rejectRing=L;this.subscribeToRouting=I;this.updateRoutingSubscription=J;this.markMessagesState=Q;this.getBrandProfile=R;this.setBrandProfile=S;this.getBrands=T;this.updateConversationsSubscription=W;this.subscribeConversations=U;this.unsubscribeConversations=V;this.setCSAT=X;this.setDelay=Y;this.setManualETTR=Z;this.restoreManualETTR=Z;this.setTTR=$;this.setNote=_;this.setTopic=aa;this.transferConversationBySkill=p;this.transferConversationByAgent=q;this.assignConversationToAgent=r;this.openDialog=ba;this.updateDialog=ca;this.getTransport=ia;this.generateURLForUploadFile=ga;this.closeDialog=ea;this.isConnected=ka;this.isWebSocketConnection=la;this.on=vb.on;this.clearAllListeners=vb.clearAllListeners;this.off=vb.off;this.emit=vb.emit;this.once=vb.once;this.events=vb.events;for(var yb in ob.events)if(ob.events.hasOwnProperty(yb)){var zb=ob.events[yb];this[zb]=Pa(zb)}};window.lpTag=window.lpTag||{};lpTag.consumerHistoryAPI=lpTag.consumerHistoryAPI||function(a){function b(a){if(a&&a.success&&A&&!G){var b={error:i.bind(this,a),queryParameters:{state:"close,archive",limit:v},type:t.CONVERSATIONS};H&&(b.queryParameters.source=H);var c=B.getProperty(a,"existingData.body._responseMetadata.count"),d=B.getProperty(a,"existingData.body.conversationHistoryMetadataRecords.length");b.queryParameters.offset=c&&d&&c>d?d:0;var g=a.success;a.existingData||(g=f.bind(this,a));b.success=e.bind(this,g,a.error,a.existingData,a.to);A.sendHistoryRequest(b);B.debug("getConversations called correctly","getConversations")}else G?B.debug("getConversations blocked","getConversations"):B.error("getConversations called incorrectly","getConversations")}function c(a){if(a&&a.success&&A&&a.conversationId&&!G)if(F[a.conversationId]&&F[a.conversationId][a.dialogId]){a.success(F[a.conversationId][a.dialogId]);delete F[a.conversationId][a.dialogId]}else if(D[a.conversationId]){E[a.conversationId]||(E[a.conversationId]=[]);E[a.conversationId].push(a)}else{D[a.conversationId]=a;var b={success:j.bind(this,a),error:s.bind(this,a),queryParameters:{conversationId:a.conversationId},type:t.MESSAGES};H&&(b.queryParameters.source=H);A.sendHistoryRequest(b);B.debug("getMessages called correctly","getMessages")}else G?B.debug("getMessages blocked","getMessages"):B.error("getMessages called incorrectly","getMessages");return a&&a.conversationId}function d(a){if(a&&a.success&&A&&a.conversationId&&a.fileId){var b={success:a.success,error:a.error,queryParameters:{conversationId:a.conversationId,fileId:a.fileId},type:t.FILE};H&&(b.queryParameters.source=H);A.sendHistoryRequest(b);B.debug("getMessages called correctly","getMessages")}else B.error("getMessages called incorrectly","getMessages");return a&&a.conversationId}function e(a,c,d,e,f){var g=f,h=B.getProperty(g,"body._responseMetadata.count"),i=B.getProperty(g,"body.conversationHistoryMetadataRecords.length");if(h&&i&&h>i&&d&&d.body&&d.body.conversationHistoryMetadataRecords){g=d;g.body.conversationHistoryMetadataRecords=g.body.conversationHistoryMetadataRecords.concat(f.body.conversationHistoryMetadataRecords);h=B.getProperty(g,"body._responseMetadata.count");i=B.getProperty(g,"body.conversationHistoryMetadataRecords.length")}h&&i&&h>i?b({success:a,error:c,existingData:g,to:e}):a(g)}function f(a,b){var c=b&&b.body&&b.body.conversationHistoryMetadataRecords||[],d=g(c),e={changes:d.map(function(a){var b={type:"UPSERT",result:{convId:a.convId,conversationDetails:{participants:a.participants,state:a.state,startTs:a.startTs,endTs:a.endTs,metaDataLastUpdateTs:a.endTs,csat:a.csat,stage:a.stage}}};b.result.conversationDetails.csat&&(b.result.conversationDetails.csat.endTs=a.endTs);b.result.conversationDetails.dialogs=a.dialogs||[{dialogId:a.convId,participantsDetails:a.participants,dialogType:C.dialog.types.MAIN,state:a.state,closedBy:a.closeReason,creationTs:a.startTs,endTs:a.endTs,channelType:C.dialog.channelTypes.MESSAGING}];return b}),code:b&&b.responseCode||b&&b.statusCode},f=e.changes;e.changes=h(f);e.changes.length>0||0===f.length?a.success.call(this,e):i.call(this,a,{responseCode:404})}function g(a){return a&&a.length>0?a.filter(function(a){a.state&&!a.stage&&(a.stage=a.state);return a.stage===C.conversation.states.CLOSE}):[]}function h(a){return a.filter(function(a){return a&&a.result&&a.result.convId&&a.result.conversationDetails&&a.result.conversationDetails.startTs&&a.result.conversationDetails.endTs&&a.result.conversationDetails.participants&&a.result.conversationDetails.participants.length>0})}function i(a,c){a.retryCount=a.retryCount||0;if(a.retryCount>=y){if(a.existingData&&a.success)a.success.call(this,a.existingData);else if(a.error){c&&(c.code=c.responseCode||c.statusCode);a.error.call(this,c)}}else{a.retryCount++;if(!a.existingData&&c&&(400===c.responseCode||400===c.statusCode)){a.to=null;delete a.to}setTimeout(function(){b.call(this,a)},w*a.retryCount)}}function j(a,b){var c,d=a&&a.success,e=a&&a.conversationId,f=a&&a.dialogId,g={changes:b&&b.body&&b.body.messageEventRecords,code:b&&b.responseCode||b&&b.statusCode};if(b&&e&&d&&p(g.changes)){g.changes.forEach(function(b){b.dialogId=b.dialogId||e;a.participants&&b.originatorId&&a.participants[b.originatorId]?b.originatorMetadata={id:b.originatorId,role:a.participants[b.originatorId].type}:b.originatorId&&(b.originatorMetadata={id:b.originatorId,role:C.participant.roles.READER})});k(g,e);c=F[e][f];d.call(this,c);delete F[e][f];m(e)}else if(g&&g.changes&&0===g.changes.length){q.call(this,a,g);o.call(this,e,g)}else{r.call(this,a,{responseCode:404});n.call(this,e,{responseCode:404})}}function k(a,b){for(var c={},d=0;d0}function q(a,b){a.retryCount=a.retryCount||0;if(a.retryCount>=z){b.dialogId=a.dialogId;a.success.call(this,b)}else{a.retryCount++;setTimeout(function(){c.call(this,a)},x*a.retryCount)}}function r(a,b){b&&(b.code=b.responseCode||b.statusCode);a.error.call(this,b)}function s(a,b){r.call(this,a,b);n.call(this,a.conversationId,b)}var t={CONVERSATIONS:"CONVERSATIONS",MESSAGES:"MESSAGES",FILE:"FILE"},u="ContentEvent",v=a.limit||50,w=a.conversationsRetryTimeout||5e3,x=a.messagesRetryTimeout||3e3,y=a.conversationsMaxRetries||3,z=a.messagesMaxRetries||3,A=a.transport,B=a.utils||lpTag.AMSUtils(),C=lpTag.AMSStatics,D={},E={},F={},G=a.blockHistory,H=a.historySource;this.getConversations=b;this.getMessages=c;this.generateDownloadURL=d};window.lpTag=window.lpTag||{};lpTag.UMSClientAPI=lpTag.UMSClientAPI||function(a){function b(a){if(a){qa=new lpTag.Chronos.Events;a.apiVersion=a.apiVersion||va;a=ka(a);la(a,xa);a=ja(a,Na);Oa=a.isFetchEnabled;sa=Oa?lpTag.taglets.fetch:lpTag.taglets.jsonp;pa?pa.reInit(a):pa=new lpTag.AMSClient(a);oa();a.historyDomain&&(Ia=new lpTag.consumerHistoryAPI({transport:pa.getTransport(),blockHistory:a.blockHistory,historySource:a.historySource,messagesMaxRetries:a.emptyHistoryConvoMaxRetries,messagesRetryTimeout:a.emptyHistoryConvoRetryTimeout}))}}function c(a){if(a){qa.unregister({appName:ta});b(a)}}function d(){pa.dispose();pa=null;qa.unregister({appName:ta});Aa={};Ba={};za=[];Ca={}}function e(a){if(Ia&&(a&&a.forceLoadFromHistoryAPI||u(a&&a.conversationId))){a.success=w.bind(this,a.conversationId);a.error=x.bind(this,a.conversationId);a.participants=Ba;return Ia.getMessages(a)}return pa.subscribeMessagingEvents(a)}function f(a){Ga.validateConditions({skillId:{type:Ga.validationTypes.NUMBER}},a)&&pa.getTransport().sendShiftStatusRequest(a)}function g(a){if(Ga.validateConditions({dialogId:{type:Ga.validationTypes.STRING}},a)){a.conversationId=Da[a.dialogId];if(ra){a.closedCause=ya.CONSUMER;return pa.closeDialog(a)}return pa.closeConversation(a)}}function h(a){ra&&(a.field=wa.conversationFields.STAGE);return pa.closeConversation(a)}function i(a){if(Ga.validateConditions({dialogId:{type:Ga.validationTypes.STRING}},a)){a.conversationId=Da[a.dialogId];return pa.sendMessage(a)}}function j(a){if(Ga.validateConditions({dialogId:{type:Ga.validationTypes.STRING}},a)){a.conversationId=Da[a.dialogId];return pa.sendPCIMessage(a)}}function k(a){if(Ga.validateConditions({dialogId:{type:Ga.validationTypes.STRING}},a)){a.conversationId=Da[a.dialogId];return pa.sendStructuredContentMessage(a)}}function l(a){if(Ga.validateConditions({dialogId:{type:Ga.validationTypes.STRING}},a)){a.conversationId=Da[a.dialogId];return pa.markMessagesState(a)}}function m(a){if(Ga.validateConditions({dialogId:{type:Ga.validationTypes.STRING}},a)){a.conversationId=Da[a.dialogId];return pa.setDialogChatState(a)}}function n(a){return Ga.validateConditions({relativePath:{type:Ga.validationTypes.STRING}},a)?Ia&&u(a.conversationId)?Ia.generateDownloadURL({fileId:a.relativePath.split("/").pop(),conversationId:a.conversationId,success:a.success,error:a.error}):pa.generateURLForDownloadFile(a):void 0}function o(a){var b,c=[],d=a.changes;ra=a.subscriptionId!==Ka?p(d):ra;q(d);if(Array.isArray(d))for(var e=0;e0?s(c,a.subscriptionId):r(a.subscriptionId)}function p(a){for(var b=0;b0)for(var c=0;c0)for(var i=ha(Ba)[0],j=0;j=k;k++){g=Y(a[j].dialogId,k);b[g]&&Z(b[g],a[j])&&f.push(k)}a[j].event.sequenceList=f}}return a}function W(a,b){var c,d=Ga.getProperty(b,"event.sequenceList");if(Array.isArray(d))for(var e=0;e=0;d--){b=O(za[d],!0);b&&za.splice(d,1)}}function da(a,b){var c=!1;for(var d in Ea)if(Ea.hasOwnProperty(d)&&Ea[d][a.userId]&&Ba[a.userId]&&Ba[a.userId].known){ea(Ba[a.userId],a,b,d);c=!0}!c&&a.known&&a.userId&&ea({},a,b)}function ea(a,b,c,d){var e=Ga.cloneExtend(a,b,!0);d&&(e.dialogId=d);c&&(e.type=c);ia(xa.PARTICIPANT_JOINED,[e]);if(!Ga.isEmpty(Ea[d])&&!Ga.isEmpty(Ea[d][a.userId])){delete Ea[d][a.userId];Ga.isEmpty(Ea[d])&&delete Ea[d]}}function fa(a){var b,c={};if(Array.isArray(a))for(var d=0;d